using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
    public class BaoCaoThuocDAO
    {
        public static bool Insert(BaoCaoThuocDTO bc)
        {
            bool kq = false;
            try
            {
                List<SqlParameter> sqlparam = new List<SqlParameter>();
                sqlparam.Add(new SqlParameter("@MaBaoCaoThuoc",bc.MaBaoCaoThuoc));
                sqlparam.Add(new SqlParameter("@NgayLapBaoCaoThuoc", bc.NgayLapBaoCaoThuoc));
                sqlparam.Add(new SqlParameter("@ThangSuDungThuoc", bc.ThangSuDungThuoc));
                int n = SqlDataAccessHelper.ExecuteNoneQuery("spBaoCaoThuocInsert", sqlparam);
                if (n == 1)
                    kq = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return kq;
        }
        public static bool Delete(BaoCaoThuocDTO bc)
        {
            bool kq = false;
            try
            {
                List<SqlParameter> sqlparam = new List<SqlParameter>();
                sqlparam.Add(new SqlParameter("@MaBaoCaoThuoc", bc.MaBaoCaoThuoc));
                
                int n = SqlDataAccessHelper.ExecuteNoneQuery("spBaoCaoThuocDelete", sqlparam);
                if (n == 1)
                    kq = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return kq;
        }
        public static bool Update(BaoCaoThuocDTO bc)
        {
            bool kq = false;
            try
            {
                List<SqlParameter> sqlparam = new List<SqlParameter>();
                sqlparam.Add(new SqlParameter("@MaBaoCaoThuoc", bc.MaBaoCaoThuoc));
                sqlparam.Add(new SqlParameter("@NgayLapBaoCaoThuoc", bc.NgayLapBaoCaoThuoc));
                sqlparam.Add(new SqlParameter("@ThangSuDungThuoc", bc.ThangSuDungThuoc));
                int n = SqlDataAccessHelper.ExecuteNoneQuery("spBaoCaoThuocUpdate", sqlparam);
                if (n == 1)
                    kq = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return kq;
        }
        public static List<BaoCaoThuocDTO> Select()
        {
            List<BaoCaoThuocDTO> lst = new List<BaoCaoThuocDTO>();
            try
            {
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spBaoCaoThuocSelect");
                foreach (DataRow dr in dt.Rows)
                {
                    BaoCaoThuocDTO bc = new BaoCaoThuocDTO();
                    bc.MaBaoCaoThuoc = int.Parse(dr["MaBaoCaoThuoc"].ToString());
                    bc.NgayLapBaoCaoThuoc = DateTime.Parse(dr["NgayLapBaoCaoThuoc"].ToString());
                    bc.ThangSuDungThuoc = DateTime.Parse(dr["ThangSuDungThuoc"].ToString());
                    lst.Add(bc);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return lst;
        }
        public static BaoCaoThuocDTO SelectByID(int MaBaoCaoThuoc)
        {
            BaoCaoThuocDTO bc = new BaoCaoThuocDTO();
            try
            {
                List<SqlParameter> sqlParam = new List<SqlParameter>();
                sqlParam.Add(new SqlParameter("@MaBaoCaoThuoc", MaBaoCaoThuoc));
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spBaoCaoThuocSelectByID",sqlParam);
                DataRow dr = dt.Rows[0];
                bc.MaBaoCaoThuoc = int.Parse(dr["MaBaoCaoThuoc"].ToString());
                bc.NgayLapBaoCaoThuoc = DateTime.Parse(dr["NgayLapBaoCaoThuoc"].ToString());
                bc.ThangSuDungThuoc = DateTime.Parse(dr["ThangSuDungThuoc"].ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return bc;
        }
    }
}


